﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace Common.Extensions
{
    public static class BMPResize
    {
        public static Bitmap Resize(this Bitmap bmp, int width, int height)
        {
            if (bmp == null || width <= 0 || height <= 0) return null;
            Bitmap result = new Bitmap(width, height);
            using (Graphics g = Graphics.FromImage((Image)result))
                g.DrawImage(bmp, 0, 0, width, height);
            return result;
        }

        public static Bitmap ResizeW(this Bitmap bmp, int width)
        {
            return bmp.Resize(width, (int)(((double)bmp.Height) / ((double)bmp.Width) * width));
        }

        public static Bitmap ResizeH(this Bitmap bmp, int height)
        {
            return bmp.Resize((int)(((double)bmp.Width) / ((double)bmp.Height) * height), height);
        }
    }
}
